package com.unnamed.b.atv.sample.ability;

import com.unnamed.b.atv.model.TreeNode;
import com.unnamed.b.atv.sample.ResourceTable;
import com.unnamed.b.atv.sample.holder.IconTreeItemHolder;
import com.unnamed.b.atv.sample.holder.ProfileHolder;
import com.unnamed.b.atv.sample.holder.HeaderHolder;
import com.unnamed.b.atv.sample.holder.SocialViewHolder;
import com.unnamed.b.atv.sample.holder.PlaceHolderHolder;
import com.unnamed.b.atv.view.OhosTreeView;
import ohos.aafwk.ability.Ability;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Text;
import ohos.agp.components.ComponentContainer;
import ohos.agp.components.Component;

/**
 * CustomViewHolderAbility
 *
 * @author Administrator
 * @Date 2021/5/26
 */
public class CustomViewHolderAbility extends Ability {
    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
        setUIContent(ResourceTable.Layout_fragment_default_ohos);
        initView();
    }

    @Override
    protected void onActive() {
        super.onActive();
    }

    private void initView() {
        ComponentContainer componentContainer = (ComponentContainer) findComponentById(ResourceTable.Id_container);
        Text statusBar = (Text) findComponentById(ResourceTable.Id_status_bar);
        statusBar.setVisibility(Component.HIDE);
        TreeNode root = TreeNode.root();
        TreeNode myProfile = new TreeNode(new IconTreeItemHolder.IconTreeItem(ResourceTable.Media_bussiness_man,
                "My Profile")).setViewHolder(new ProfileHolder(getContext()));
        TreeNode bruce = new TreeNode(new IconTreeItemHolder.IconTreeItem(ResourceTable.Media_bussiness_man,
                "Bruce Wayne")).setViewHolder(new ProfileHolder(getContext()));
        TreeNode clark = new TreeNode(new IconTreeItemHolder.IconTreeItem(ResourceTable.Media_bussiness_man,
                "Clark Kent")).setViewHolder(new ProfileHolder(getContext()));
        TreeNode barry = new TreeNode(new IconTreeItemHolder.IconTreeItem(ResourceTable.Media_bussiness_man,
                "Barry Allen")).setViewHolder(new ProfileHolder(getContext()));
        addProfileData(myProfile);
        addProfileData(clark);
        addProfileData(bruce);
        addProfileData(barry);
        root.addChildren(myProfile, bruce, barry, clark);
        OhosTreeView tView = new OhosTreeView(this, root);
        componentContainer.addComponent(tView.getView());
    }

    private void addProfileData(TreeNode profile) {
        TreeNode socialNetworks = new TreeNode(new IconTreeItemHolder.IconTreeItem
                (ResourceTable.Media_customer_management_fill, "Social")).setViewHolder(new HeaderHolder(getContext()));
        TreeNode places = new TreeNode(new IconTreeItemHolder.IconTreeItem(ResourceTable.Media_address,
                "Places")).setViewHolder(new HeaderHolder(getContext()));
        TreeNode facebook = new TreeNode(new SocialViewHolder.SocialItem(ResourceTable.Media_facebook))
                .setViewHolder(new SocialViewHolder(getContext()));
        TreeNode linkedin = new TreeNode(new SocialViewHolder.SocialItem(ResourceTable.Media_google))
                .setViewHolder(new SocialViewHolder(getContext()));
        TreeNode google = new TreeNode(new SocialViewHolder.SocialItem(ResourceTable.Media_twitter))
                .setViewHolder(new SocialViewHolder(getContext()));
        TreeNode twitter = new TreeNode(new SocialViewHolder.SocialItem(ResourceTable.Media_in))
                .setViewHolder(new SocialViewHolder(getContext()));
        socialNetworks.addChildren(facebook, google, twitter, linkedin);
        TreeNode lake = new TreeNode(new PlaceHolderHolder.PlaceItem("A rose garden"))
                .setViewHolder(new PlaceHolderHolder(getContext()));
        TreeNode mountains = new TreeNode(new PlaceHolderHolder.PlaceItem("The white house"))
                .setViewHolder(new PlaceHolderHolder(getContext()));
        places.addChildren(lake, mountains);
        profile.addChildren(socialNetworks, places);
    }
}
